#include "game_ev.h"
#include "game_log.h"
#include <event2/event.h>
#include <event2/thread.h>
#include <stdio.h>

void __ev_log(int severity, const char *msg){
  const char *s;

  switch (severity)
  {
  case _EVENT_LOG_DEBUG:
    s = "debug";
    break;
  case _EVENT_LOG_MSG:
    s = "msg";
    break;
  case _EVENT_LOG_WARN:
    s = "warn";
    break;
  case _EVENT_LOG_ERR:
    s = "error";
    break;
  default:
    s = "?";
    break; /* never reached */
  }
  __log("[%s] %s\n", s, msg);
}

void __ev_config(){
  event_set_log_callback(__ev_log);
  event_enable_debug_logging(EVENT_DBG_NONE);
  // event_enable_debug_mode();
}

event_base* CGameEV::getBase(){
  if(NULL == _evbase){
    evthread_use_pthreads();
    _evbase = event_base_new();
  }
  return _evbase;
}

CGameEV g_CGameEV;
